package com.shang.service.impl;

import com.shang.dao.impl.UserDaoImpl;
import com.shang.dto.UserLookDTO;
import com.shang.entity.User;
import com.shang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDaoImpl userDao;

    @Override
    public List<UserLookDTO> getUsersByPage(int pageNum, int pageSize) {
        List<User> userList = userDao.getUsersByPage(pageNum, pageSize);
        List userLookList =new ArrayList();
        for (User user : userList) {
            UserLookDTO userLookDTO=new UserLookDTO();
            userLookDTO.setUserName(user.getUserName());
            userLookDTO.setRole(user.getRole());
            userLookDTO.setTelephone(user.getTelephone());
            userLookList.add(userLookDTO);
        }
        return userLookList;
    }

    @Override
    public int getUserNumber() {
       return userDao.getUserNumber();
    }

    @Override
    public int deleteUserByName(String userName) {
        int user = userDao.deleteUserByName(userName);
        return user;
    }

    @Override
    public List<User> getUserByName(String userName) {
        List<User> userByName = userDao.getUserByName(userName);
        return userByName;
    }
}
